﻿import pyback, os

def list_backup(dest, maxdepth, depth=1):
    list_of_dirs = []
    try:
        names = os.listdir(dest)
    except os.error:
        return False
    names.sort()
    for name in names:
        new_dest = os.path.join(dest, name)
        if maxdepth<>depth:
            list_of_dirs.extend(filter_backup(new_dest, filters, maxdepth, depth+1))
        else:
            list_of_dirs.append(new_dest)
    return list_of_dirs

def filter_backup2(dest):
    names = os.listdir(dest)
    for name in names:
        filter_backup2(os.path.join(dest, name))
    yield names

def main():
    dest = "C:\\temp\\Backup\\MEDIA"
    Filter = {'d': '4444', 'h': '55555', 'M': '22', 'm': '666666', 'w': '333', 'y': '1'}

##    for fb in filter_backup2(dest):
##        print fb
    fb = filter_backup(dest, Filter, 5)
##    print(os.path.exists(dest))
##    print "===>",str(fb)
    print
    for I in fb:
        print I
    pass

if __name__ == '__main__':
    main()
